<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('会计科目')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i>会计科目
				</div>
				<div class="box-tools pull-right">
				    <a type="button" class="btn btn-box-tool" href="#"  title="会计科目"><i class="fa fa-edit"></i></a>
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新科目"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="formId">
                    <div class="select-list">
                        <ul>
                           <li>
								<label>核算年度：</label>
								<select name="nd" id="nd">
									<option th:each="nd : ${ndlist}" th:text="${nd}" th:value="${nd}"></option>
								</select>
							</li>
                           <li>
                                <label>会计科目：</label>
                                <input type="text" name="kmdm"/>
                            </li>
                            <li>
                                <label>科目名称：</label>
                                <input type="text" name="kmmc"/>
                            </li>
                            <li>
                                <label>上级科目：</label>
                                <input type="text" name="sjkmdm" id="sjkmdm"/>
                            </li>
                            <li>
                                <label>科目类型：</label>
                                <select name="kmlx" >
                                    <option value="">全部</option>
								    <option value="1">资产</option>
									<option value="2">负债</option>
									<option value="3">净资产</option>
									<option value="4">收入</option>
									<option value="5">支出</option>
								</select>
                            </li>
                            <li>
                                <label>借贷方向：</label>
                                 <select name="jdfx" >
                                    <option value="">全部</option>
								    <option value="1">借</option>
									<option value="-1">贷</option>
								</select>
                            </li>
                            <li>
                                <label>科目级别：</label>
                                <input type="text" name="kmjb"/>
                            </li>
                            <li>
                                <label>科目结构：</label>
                                <input type="text" name="kmjg"/>
                            </li>
                            <li>
                                <label>是否末级：</label>
                                <select name="sfmj" >
                                    <option value="">全部</option>
								    <option value="0">是</option>
									<option value="1">否</option>
								</select>
                            </li> 
                            <li>
                                <label>科目别名：</label>
                                <input type="text" name="kmbm"/>
                            </li>
                            <li>
                               <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							   <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
				</div>
				
		        <div class="btn-group-sm" id="toolbar" role="group">
		        	<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:kmdm:add">
                    <i class="fa fa-plus"></i> 新增
					</a>
					<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:kmdm:edit">
						<i class="fa fa-edit"></i> 修改
					</a>
		            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:kmdm:remove">
		                <i class="fa fa-remove"></i> 删除
		            </a>
		        </div>
		        
		        <div class="col-sm-12 select-table">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var addFlag = [[${@permission.hasPermi('system:kmdm:add')}]];
        var editFlag = [[${@permission.hasPermi('system:kmdm:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:kmdm:remove')}]];
        var prefix = ctx + "system/kmdm";
    	$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 350 });
		    queryList();
		    queryTree();
		});

		function queryList() {
			var options = {
	                url: prefix + "/list",
	                createUrl: prefix + "/add/{id}",
	                updateUrl: prefix + "/edit/{id}",
	                removeUrl: prefix + "/remove/{id}",
	                exportUrl: prefix + "/export",
	                modalName: "会计科目",
	                columns: [{
			            checkbox: true
			        },{
	                    field: 'kmdm',
	                    title: '科目代码',
	                    align: 'left'
	                },
	                {
	                    field: 'kmmc',
	                    title: '科目名称',
	                    align: 'left'
	                },
	                {
	                    field: 'kmlx',
	                    title: '科目类型',
	                    align: 'left',
			        	formatter: function (value, row, index) {
			        		return kmlx(row);
			        	}
	                },
	                {
	                    field: 'jdfx',
	                    title: '借贷方向',
	                    align: 'left',
			        	formatter: function (value, row, index) {
			        		return jdfx(row);
			        	}
	                },
	                {
	                    field: 'kmjb',
	                    title: '科目级别',
	                    align: 'left'
	                },
	                {
	                    field: 'kmjg',
	                    title: '科目结构',
	                    align: 'left'
	                },
	                {
	                    field: 'sfmj',
	                    title: '是否末级',
	                    align: 'left',
			        	formatter: function (value, row, index) {
			        		return sfmj(row);
			        	}
	                },
	                {
	                    field: 'fzhsdw',
	                    title: '是否辅助核算单位',
	                    align: 'left',
			        	formatter: function (value, row, index) {
			        		return fzhsdw(row);
			        	}
	                },
	                {
	                    field: 'kmbm',
	                    title: '科目别名',
	                    align: 'left'
	                },
	                {
	                    field: 'sjkmdm',
	                    title: '上级科目代码',
	                    align: 'left'
	                },
	                {
	                    title: '操作',
	                    align: 'center',
	                    align: 'left',
	                    formatter: function(value, row, index) {
	                        var actions = [];
	                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.kmdm + '\')"><i class="fa fa-edit"></i>编辑</a> ');
	                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.kmdm + '\')"><i class="fa fa-plus"></i>新增</a> ');
	                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.kmdm + '\')"><i class="fa fa-remove"></i>删除</a>');
	                        return actions.join('');
	                    }
	                }]
	            };
			$.table.init(options);
		}
		 
		function jdfx(row) {
		    if (row.jdfx == 1) {
		    	return '<span class="label label-primary">借</span> ';	
    		}else if (row.jdfx == -1) {
		    	return '<span class="label label-primary">贷</span> ';	
    		}else if (row.jdfx == 2) {
		    	return '<span class="label label-primary">借或贷</span> ';	
    		}
		}
		function kmlx(row) {
		    if (row.kmlx == 1) {
		    	return '<span class="label label-primary">资产</span> ';	
    		}else if (row.kmlx == 2) {
		    	return '<span class="label label-primary">负债</span> ';	
    		}else if (row.kmlx == 3) {
		    	return '<span class="label label-primary">净资产</span> ';	
    		}else if (row.kmlx == 4) {
		    	return '<span class="label label-primary">收入 </span> ';	
    		}else if (row.kmlx == 5) {
		    	return '<span class="label label-primary">支出</span> ';	
    		}
		}
		
		function sfmj(row) {
		    if (row.sfmj == 0) {
		    	return '<i class=\"fa fa-toggle-on text-info fa-2x\"></i> ';
    			
    		} else {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\"></i> ';
    		}
		}
	
		function fzhsdw(row) {
		    if (row.fzhsdw == 0) {
		    	return '<span class="label label-primary">无</span> ';	
    		} else if (row.fzhsdw == 1) {
		    	return '<span class="label label-primary">会计科目-单位</span> ';	
    		}else if (row.fzhsdw == 2) {
		    	return '<span class="label label-primary">会计科目-单位-预算科目</span> ';	
    		}else if (row.fzhsdw == 3) {
		    	return '<span class="label label-primary">会计科目-预算科目</span> ';	
    		}
		}
		
		function queryTree()
		{
			var url = ctx + "system/kmdm/listtreeData/"+$('#nd').val();
			var options = {
		        url: url,
		        expandLevel: 2,
		        onClick : zOnClick
		    };
			$.tree.init(options);
			function zOnClick(event, treeId, treeNode) {
				$("#sjkmdm").val(treeNode.pId);
				$.table.search();
			}
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryTree();
		});
		$("#nd").change(function(){
			queryTree();
    		$.table.search();
		});
	</script>
</body>
</html>